/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/


#include "geofence_location.h"

namespace OHOS {
namespace Msdp {

void GeofenceLocation::GeofenceCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
    if (remote == nullptr) {
        GEOFENCE_HILOGE(GEOFENCE_MODULE_SERVICE, "OnRemoteDied failed, remote is nullptr");
        return;
    }
    GEOFENCE_HILOGD(GEOFENCE_MODULE_SERVICE, "Recv death notice");
}

bool GeofenceLocation::Init()
{
    GEOFENCE_HILOGI(GEOFENCE_MODULE_SERVICE, "GeofenceLocation: Init start");
    if (geofenceCBDeathRecipient_ == nullptr) {
        geofenceCBDeathRecipient_ = new GeofenceCallbackDeathRecipient();
    }
    GEOFENCE_HILOGI(GEOFENCE_MODULE_SERVICE, "GeofenceLocation: Init success");
    return true;
}

bool GeofenceLocation::InitLocationDataCallback(std::shared_ptr<GeofenceImplClient> geofenceImplClient_,
    CallbackLocationData callbackLocationData)
{
    GEOFENCE_HILOGE(GEOFENCE_MODULE_SERVICE, "enter");
    callbacksLocationData_ = callbackLocationData;

    if (geofenceImplClient_ != nullptr) {
        GeofenceImplClient::CallbackLocationManager callback = std::bind(&GeofenceLocation::LocationCallback,
            this, std::placeholders::_1);
        geofenceImplClient_->RegisterLocationImpl(callback);
        GEOFENCE_HILOGI(GEOFENCE_MODULE_SERVICE, "Init success create rdb location manager");
    }
    GEOFENCE_HILOGI(GEOFENCE_MODULE_SERVICE, "exit");
    return true;
}

int32_t GeofenceLocation::LocationCallback(GeofenceDataUtils::LocationData& locationData)
{
    GEOFENCE_HILOGI(GEOFENCE_MODULE_SERVICE, "enter");
    callbacksLocationData_(locationData);
    GEOFENCE_HILOGI(GEOFENCE_MODULE_SERVICE, "exit");
    return 1;
}


} // namespace Msdp
} // namespace OHOS

